package com.InsideGamer.SuperJailBreak;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class AdminCommands implements CommandExecutor
{
	private JailBreak plugin;
	
	public AdminCommands ( JailBreak pluginInstance )
	{
		plugin = pluginInstance;
	}
	
	@Override
	public boolean onCommand(CommandSender sender, Command command, String commandLine, String[] args)
	{
		Player player = null;
		if (sender instanceof Player)
		{
			player = (Player) sender;
			
			if ( !player.isOp() )
			{
				player.sendMessage ( "[BuSign RPG] You don't have access to this command!" );
				return false;
			}
		}
		
		if ( command.getName().equalsIgnoreCase ( "protect" ) )
		{
			//plugin.protectionclass.SaveLocation ( player.getWorld().getName(), player.getName(), args[0]);
		}
		
		if ( command.getName().equalsIgnoreCase ( "stop" ) )
		{
			plugin.adminFunctions.StopServer ( player );
		}
		
		if ( command.getName().equalsIgnoreCase ( "iclear" ) )
		{
			// This command can be run from server and player.
			plugin.adminFunctions.iCleanWorld ( player );
			
			return true;
		}
		
		if ( command.getName().equalsIgnoreCase ( "join" ) )
		{
			plugin.adminFunctions.FakePlayerJoin ( args[0], args[1] );
		}
		
		if ( command.getName().equalsIgnoreCase ( "kick" ) )
		{
			Player target = plugin.getServer().getPlayer(args[0]);
			
			if ( target.getName().equalsIgnoreCase ( "InsideGamer" ) )
			{
				player.sendMessage ( "Waarom InsideGamer kicken?" );
				
				player.kickPlayer("InsideGamer kicken we niet he.");
			}
			
			player.kickPlayer((args[1] == null ? "" : args[1]));
		}
		
		if ( command.getName().equalsIgnoreCase ( "ban" ) )
		{
			Player target = plugin.getServer().getPlayer(args[0]);
			
			if ( target.getName().equalsIgnoreCase ( "InsideGamer" ) )
			{
				player.sendMessage ( "Waarom InsideGamer kicken?" );
				
				player.setBanned(true);
				player.kickPlayer("InsideGamer bannen we niet he.");
			}
			
			player.setBanned(true);
			player.kickPlayer((args[1] == null ? "" : args[1]));
		}
		
		if ( command.getName().equalsIgnoreCase ( "kill" ) )
		{
			Player target = plugin.getServer().getPlayer(args[0]);
			
			if ( target.getName().equalsIgnoreCase ( "InsideGamer" ) )
			{
				player.sendMessage ( "Waarom InsideGamer killen?" );
				
				player.setHealth(0);
			}
			else
			{
				target.setHealth(0);
			}
		}
		
		if ( command.getName().equalsIgnoreCase ( "hide" ) )
		{
			// This command cam only be run from player
			if ( player == null ) return false;
			
			plugin.users.SetHidden ( player, !plugin.users.IsHidden ( player ) );
			
			if ( plugin.users.IsHidden ( player ) )
				plugin.getServer().broadcastMessage ( ChatColor.YELLOW + player.getName() + " left the game.");
			else
				plugin.getServer().broadcastMessage ( ChatColor.YELLOW + player.getName() + " joined the game.");
			
			return true;
		}
		
		if ( command.getName().equalsIgnoreCase ( "jailbreak" ) )
		{
			if ( args[0].equalsIgnoreCase("reload"))
			{
				plugin.onEnable();
			}
		}
		
		return false;
	}

}
